// WebScriptCall.h: interface for the CWebScriptCall class.
//
//////////////////////////////////////////////////////////////////////

#pragma once

#pragma warning(disable: 4251)

class ExportXSkinLib CWebScriptCall
{
public:
	CWebScriptCall();
	virtual ~CWebScriptCall();

	bool SetDocument(IDispatch* pDisp);
	const XString GetLastError() const;
	bool GetJScript(XPtr<IDispatch>& spDisp);
	bool GetJScripts(XPtr<IHTMLElementCollection>& spColl);

	XString ScanJScript(XString& strAText, XStringVector& args);

	bool CallJScript(const XString strFunc,_variant_t* pVarResult = NULL);
	bool CallJScript(const XString strFunc,const XString strArg1,_variant_t* pVarResult = NULL);
	bool CallJScript(const XString strFunc,const XString strArg1,const XString strArg2,_variant_t* pVarResult = NULL);
	bool CallJScript(const XString strFunc,const XString strArg1,const XString strArg2,const XString strArg3, _variant_t* pVarResult = NULL);
	bool CallJScript(const XString strFunc,const XStringVector& paramArray,_variant_t* pVarResult = NULL);

protected:
	void ShowError(LPCTSTR lpszText);

protected:
	XPtr<IHTMLDocument2>	m_spDoc;
	XString	m_strError;
};

inline
void CWebScriptCall::ShowError(LPCTSTR lpszText)
{
	m_strError = XString(_T("JSCall Error:\n")) + XString(lpszText);
}
inline 
const XString CWebScriptCall::GetLastError() const
{
	return m_strError;
}

XString GetNextToken(XString& strSrc, const XString strDelim,bool bTrim = false, bool bFindOneOf = true);

